import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:ts_app_dart/widget/popup_window.dart';

class AnimationPage extends StatefulWidget {
  const AnimationPage({Key key}) : super(key: key);

  @override
  _AnimationPageState createState() => _AnimationPageState();
}

class _AnimationPageState extends State<AnimationPage> {
  final message = """
    如果发出声音是危险的，那就保持沉默;
    如果自觉无力发光，那就别去照亮别人。
    但是——不要习惯了黑暗就为黑暗辩护;
    不要为自己的苟且而得意洋洋;
    不要嘲讽那些比自己更勇敢、更有热量的人们。
    我们可以卑微如尘土，不可扭曲如蛆虫。
    ——曼德拉《漫漫人生路》
    """;

  void showCustomAlert() {
    Navigator.push(
      context,
      NPopupRoute(
        alignment: Alignment.topCenter,
        onClick: () {
          Navigator.of(context).pop();
        },
        child: GestureDetector(
          onTap: () {},
          child: Container(
            margin: EdgeInsets.only(top: 360.0),
            width: 320.0,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular((10.0)), // 圆角度
            ),
            child: Padding(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: EdgeInsets.all(6),
                    child: Text(
                      'This is a Title',
                      style: TextStyle(fontWeight: FontWeight.w600),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(6),
                    child: Text(
                      message,
                      style: TextStyle(fontWeight: FontWeight.w300),
                    ),
                  ),
                ],
              ),
              padding: EdgeInsets.all(12),
            ),
          ),
        ).animate().fade(duration: 500.ms).scale(),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('AnimationPage'),
      ),
      body: Column(children: [
        Container(
          child: Column(children: [
            Container(
              child: Center(
                child: Text('This is a example'),
              ),
              height: 60.0,
            ),
            Container(
              height: 60.0,
              child: Text('This is a example')
                  .animate()
                  .fade(duration: 500.ms)
                  .scale(delay: 500.ms), // 在淡入淡出之后运行
            ),
          ]),
        ),
        Container(
          child: TextButton(
            onPressed: showCustomAlert,
            child: Text('Toggle Dialog'),
          ),
        )
      ]),
    );
  }
}
